<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>我的订单-{{$SEO['title']}}</title>
    <meta name="keywords" content="{{$SEO['keywords']}}"/>
    <meta name="description" content="{{$SEO['description']}}"/>
    <!--公用css引用-->
    @include('front.common.style')
    <!--END/公用css引用-->
    <link rel="stylesheet" href="{{ asset("/dist/css/userCenter.css") }}">
</head>
<body>
@inject('request','Illuminate\Http\Request')

<!--公共头部-->
@include('front.common.header')
        <!--END/公共头部-->

<div class="inbox user-center">
    <div class="layout-margin unend">
        <div class="sidebar-end"></div>
        <div class="sidebar-start">
            @include('front.common.leftnav')
        </div>
@inject('pictureService','App\Interfaces\PictureService')
@inject('orderService','App\Interfaces\OrderService')
@inject('refundGoodsService','App\Interfaces\RefundGoodsService')


        <!--主体部分-->
        <div class="container">
            <div class="container-inner u-order">
                <div class="">
                    <div class="tit-2 tit-skin-2">
                        <span class="h">我的订单</span>
                    </div>

                    <div id="orderListSel" class="order-list order-list-big">
                        <div class="table-head fn-ohide">
                            <div class="search-box">

                                    <div class="fn-dib fn-rel keybox">
                                        <input type="text" name="key" id="key" placeholder="订单号" autocomplete="off" class="fn-tinput key">
                                        <span class="fn-dib submit">
                                            <button class="fn-btn btn-submit btn-search">查询</button>
                                        </span>
                                        <i class="icon icon-search fn-abs"></i>
                                    </div>
                            </div>
                            <div class="order-type">
                                <ul class="link-list link-list-skin2">
                                    <li @if(!$request->exists('order_status')) class="cur" @endif><a href="/my/order">全部订单</a></li>
                                    <li @if($request->exists('order_status') && $request->input('order_status')=='1') class="cur" @endif><a href="/my/order?order_status=1">待付款（{{$orderService->countOrders($user->id,1)}}）</a></li>
                                    <li @if($request->exists('order_status') && $request->input('order_status')=='3') class="cur" @endif><a href="/my/order?order_status=3">待收货（{{$orderService->countOrders($user->id,3)}}）</a></li>
                                    <li @if($request->exists('comment_status') && $request->input('comment_status')=='0') class="cur" @endif><a href="/my/order?order_status=4&comment_status=0">待评价（{{$orderService->countOrders($user->id,4)}}）</a></li>
                                </ul>
                            </div>

                        </div>
                        <div class="js-tools order-list-head">
                            <table class="bl-table bl-table-white table-tc">
                                <thead>
                                <tr>
                                    <th class="tl">
                                        <div class="bl-ddmenu ddmenu-select">
                                            <a class="menu-btn" style="width: 122px;">
                                                <span class="text">近三个月订单</span>
                                                <i class="ficon-arr-b"><i class="icon f-icon icon-arrow-b1 "></i></i>
                                            </a>
                                            <div class="menu-con">
                                            <?php
                                                $status='';
                                                if($filter['order_status']){
                                                    $status='&order_status='.$filter['order_status'];
                                                }
                                                if(isset($filter['comment_status'])){
                                                    $status=$status.'&comment_status='.$filter['comment_status'];
                                                }
                                            ?>
                                                <ul class="menu-list">
                                                    <li data-value="1"><a href="/my/order?date=1{{$status}}">近三个月订单</a></li>
                                                    <li data-value="2"><a href="/my/order?date=2{{$status}}">近六个月订单</a></li>
                                                    <li data-value="3"><a href="/my/order?date=3{{$status}}">2016年订单</a></li>
                                                    <li data-value="4"><a href="/my/order?date=4{{$status}}">2015年订单</a></li>
                                                    <li data-value="5"><a href="/my/order?date=5{{$status}}">2015年以前</a></li>
                                                </ul>
                                            </div>
                                            <input type="text" name="date" value="{{$filter['date']}}" class="menu-input">
                                        </div>
                                    </th>
                                    <th>订单详情</th>
                                    <th style="width: 100px;">收货人</th>
                                    <th style="width: 100px;">合计</th>
                                     @if($filter['order_status']==4 && isset($filter['comment_status']))
                                     <th style="width: 100px;">全部状态</th>
                                     @else
                                    <th style="width: 100px;">
                                        <div class="bl-ddmenu ddmenu-select">
                                            <a class="menu-btn" style="width: 100px;"><span class="text">全部状态</span><i class="ficon-arr-b"><i class="icon f-icon icon-arrow-b1 "></i></i></a>
                                            <div class="menu-con">

                                            <?php
                                                $status='';
                                                if($filter['date']){
                                                    $status='&date='.$filter['date'];
                                                }
                                                if(isset($filter['comment_status'])){
                                                    $status=$status.'&comment_status='.$filter['comment_status'];
                                                }
                                            ?>
                                                <ul class="menu-list">
                                                    <li data-value="all"><a href="/my/order">全部状态</a></li>
                                                    <li data-value="1"><a href="/my/order?order_status=1{{$status}}">等待付款</a></li>
                                                    <li data-value="3"><a href="/my/order?order_status=3{{$status}}">等待收货</a></li>
                                                    <li data-value="4"><a href="/my/order?order_status=4{{$status}}">已完成</a></li>
                                                    <li data-value="5"><a href="/my/order?order_status=5{{$status}}">已取消</a></li>
                                                </ul>

                                            </div>
                                            <input type="text" name="status" value="{{$filter['order_status']}}" class="menu-input">
                                        </div>
                                    </th>
                                     @endif
                                    <th style="width: 100px;">操作</th>
                                </tr>
                                </thead>
                                @if($query->count())
                                <tr class="list-tools">
                                    <td class="tl" colspan="8">
                                        <!--分页-->
                                        <!--  fn-tl/fn-tc/fn-tr 左中右定位; pager-big 大尺寸分页 可不加-->

                                        <div class="pager fn-tr fn-fr">
                                            <ul class="pagination">
                                                {!! $query->appends($filter)->render() !!}
                                            </ul>
                                        </div>

                                        <!--END/分页-->

                                    </td>
                                </tr>
                                @endif
                            </table>

                        </div>
                        @if($query->count())
                        <div class="js-viewBox order-list-body">
                            @foreach($query as $key=>$order)

                                <div class="inner-body">
                                <table class="bl-table bl-table-white table-tc">

                                <tr data-id="{{$order->order_id}}" class="@if($order->order_status==1) list-item @endif table-inner-head">
                                    <td colspan="8" class="tl">
                                        <a href="javascript:;" data-id="{{$order->order_id}}" class="js-delBtn del fn-fr fn-mr10" title="删除订单"><i class="icon icon-del1"></i></a>

                                        <span class="time">{{$order->add_time}}</span>
                                        <span class="order-id">订单号：{{$order->order_sn}}</span>
                                        <div class="fn-dib hover-show-tip fn-rel">
                                            <i class="icon icon-qq-blue-sm fn-mr4" style="margin-top: -3px;"></i>

                                            <div class="bl-tip-box tip-skin-gray" style="left: -59px;top:24px;width:120px; ">
                                                <div class="mask-T"></div>
                                                <div class="J-box TJ-box"><span class="J"></span><i class="J"></i></div>
                                                <div class="bl-tip-con">
                                                    <ul>
                                                        <li>
                                                            <a class="js-qq" data-qq="3039215126" href="http://wpa.qq.com/msgrd?v=3&amp;uin=3039215126&amp;site=qq&amp;menu=yes" target="_blank" title="离线"><i class="icon icon-qq-gray-sm fn-mr4" style="margin-top: -3px;"></i>客服-小阿</a>
                                                        </li>
                                                        <li>
                                                            <a class="js-qq" data-qq="1378461406" href="http://wpa.qq.com/msgrd?v=3&amp;uin=1378461406&amp;site=qq&amp;menu=yes" target="_blank" title="离线"><i class="icon icon-qq-gray-sm fn-mr4" style="margin-top: -3px;"></i>客服-小福</a>
                                                        </li>
                                                        <li>
                                                            <a class="js-qq" data-qq="2151543159" href="http://wpa.qq.com/msgrd?v=3&amp;uin=2151543159&amp;site=qq&amp;menu=yes" target="_blank" title="离线"><i class="icon icon-qq-gray-sm fn-mr4" style="margin-top: -3px;"></i>客服-小易</a>
                                                        </li>
                                                        <li>
                                                            <a class="js-qq" data-qq="3082657948" href="http://wpa.qq.com/msgrd?v=3&amp;uin=3082657948&amp;site=qq&amp;menu=yes" target="_blank" title="离线"><i class="icon icon-qq-gray-sm fn-mr4" style="margin-top: -3px;"></i>客服-小塔</a>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </div>

                                    </td>
                                </tr>
                                <?php $goodsList=$orderService->getOrderGoods($order->order_id); $goodsCount=$goodsList->count(); ?>
                                @foreach($goodsList as $orderGoodskey=>$orderGoods)
                                <?php $notLast= ($orderGoodskey+1 < $goodsCount); ?>

                                <tr>
                                    <td class="pic tl " style="width:64px;">
                                        <a href="/goods/{{$orderGoods->goods_id}}" target="_blank" title="{{$orderGoods->goods_name}}">
                                            <img class="head-img" src="{{$pictureService::thumb($orderGoods->goods_thumb, 70, 70)}}" alt="#">
                                        </a>

                                        @if($notLast)
                                        <span class="borb"></span>
                                        @endif
                                    </td>
                                    <td class="tl name ">

                                        <p>
                                            <a class="link" href="/goods/{{$orderGoods->goods_id}}" target="_blank" title="{{$orderGoods->goods_name}}">{{$orderGoods->goods_name}}</a>
                                            <a class="link fn-db fn-mt4" href="{{route('front.goods.archive', [ $orderService->getByOrderId($orderGoods->order_id)->order_sn,$orderGoods->goods_id])}}" target="_blank"><span class="t-info">[交易快照]</span></a>
                                        </p>

                                        @if($notLast)
                                            <span class="borb"></span>
                                        @endif
                                    </td>
                                    <td class="tr">

                                        <span>×{{$orderGoods->buy_number}}</span>
                                        @if($notLast)
                                            <span class="borb"></span>
                                        @endif
                                    </td>
                                    <td class="ui-brd-r" style="width:60px;">
                                        <?php
                                        $refundGoods = $refundGoodsService->getByOrderSnGoodsSn($order->order_sn, $orderGoods->goods_sn);

                                            switch($refundGoods['refund_status']){
                                                case 1:
                                                    echo '审核中';
                                                    break;
                                                case 2:
                                                    echo '处理中';
                                                    break;
                                                case 3:
                                                    echo '退货完成';
                                                    break;
                                                case 4:
                                                    echo '退货审核不通过';
                                                    break;
                                                case 5:
                                                    echo '退货申请已取消';
                                                    break;
                                            }
                                        ?>
                                        @if($order->order_status==4 && empty($refundGoods))
                                            <!-- <a href="{{route('my.refund.apply',[$order->order_sn,$orderGoods->goods_id])}}" >退货</a> -->
                                            <a href="/my/refund/apply/{{$order->order_sn}}/{{$orderGoods->goods_id}}" >退货</a>
                                        @endif

                                        @if($notLast)
                                            <span class="borb"></span>
                                        @endif

                                    </td>
                                   @if($orderGoodskey==0)
                                    <td class="ui-brd-r" rowspan="{{$goodsCount}}" style="width: 100px;">
                                        <span class="u-name">{{$order->consignee}} <i class="icon icon-user-sm"></i></span>
                                    </td>

                                    <td class="ui-brd-r @if($order->coupon_price&&$order->coupon_price>0) tl @endif" rowspan="{{$goodsCount}}" style="width: 160px;">
                                        @if($order->coupon_price&&$order->coupon_price>0)
                                            优惠券<span class="text-color-1 fn-ml10">-￥{{$order->coupon_price}}</span>
                                            <br>
                                        @endif
                                        @if($order->discount_price&&$order->discount_price>0)
                                            折<span class="w-1em"></span>扣<span class="text-color-1 fn-ml10">-￥{{$order->discount_price}}</span>
                                            <br>
                                        @endif
                                        应<span class="w-1em"></span>付<span class="text-color-1 fn-ml10">￥{{$order->pay_price}}</span><br>
                                    </td>
                                    <?php $orderStatusArr = ['0'=>'状态', '1'=>'待支付','2'=>'待发货','3'=>'已发货','4'=>'已完成','5'=>'已取消','6'=>'已退款'];?>
                                    <td class="ui-brd-r" rowspan="{{$goodsCount}}" style="width: 100px;">

                                            <span class="text-color-7">
                                            {{$orderStatusArr[$order->order_status]}}
                                            </span><br>
                                            <a class="link" href="/my/order/{{$order->order_id}}" target="_blank">订单详情</a>


                                    </td>
                                    <td rowspan="{{$goodsCount}}" style="width: 100px;">
                                        @if($order->order_status==1)
                                            <!--时间赋值成秒数 data-time="xx" xx为秒数-->
                                            @if(($order->pay_left_time)>0)
                                            <div class="J-wrap">
                                                <span class="js-countDown text-color-danger" data-time="{{$order->pay_left_time}}">0天0小时0分0秒</span><span>后关闭</span>
                                            </div>
                                            @endif
                                            <a  class="fn-btn fn-btn-pay btn-primary" data-id="{{$order->order_id}}"  href="/pay/{{$order->order_id}}">立即支付</a><br>
                                            <a href="javascript:;" data-id="{{$order->order_id}}" class="js-cancelOrder fn-btn-cancel link">取消订单</a>

                                        @elseif($order->order_status==2)
                                            <a  class="fn-btn fn-btn-payagain" data-id="{{$order->order_id}}" data-goCart="true" href="javascript:;">再次购买</a>
                                            {{--<a  class="J-payagain-cart buy-link link" data-id="{{$order->order_id}}" data-goCart="true" href="javascript:;">再次购买</a>--}}
                                        @elseif($order->order_status==3)
                                            <a  class="fn-btn fn-btn-receive" data-id="{{$order->order_id}}"  href="javascript:;">确认收货</a><br>

                                        @elseif($order->order_status==4)
                                            @if($order->comment_status==0)
                                            <a class="link" href="/my/comment">评价晒单</a><br>
                                            @elseif($order->comment_status==1)
                                            <a>已评价</a><br>
                                            @endif
                                            <a  class="fn-btn fn-btn-payagain" data-id="{{$order->order_id}}" data-goCart="true" href="javascript:;">再次购买</a>
                                            {{--<a  class="J-payagain-cart buy-link link" data-id="{{$order->order_id}}" data-goCart="true" href="javascript:;">再次购买</a>--}}
                                        @elseif($order->order_status==5 || $order->order_status==6)
                                            <a  class="fn-btn fn-btn-payagain" data-id="{{$order->order_id}}" data-goCart="true" href="javascript:;">再次购买</a>
                                            {{--<a  class="J-payagain-cart buy-link link" data-id="{{$order->order_id}}" data-goCart="true" href="javascript:;">再次购买</a>--}}
                                        @endif
                                    </td>
                                   @endif
                                </tr>
                                @endforeach

                                </table>
                                </div>
                            @endforeach

                        </div>
                        @else
                        <div class="order-list-foot">
                            <div class="bl-nodata order-nodata">
                                <div class="nodata-text fn-dib">
                                    <i class="icon icon-nodata icon-nodata-1"></i>
                                    <p class="fn-mb0">无订单</p>
                                    <a href="/">去看看有哪些热门商品 &gt;</a>
                                </div>
                            </div>
                        </div>
                        @endif

                    </div>

                    <!--分页-->

                    <!--  fn-tl/fn-tc/fn-tr 左中右定位; pager-big 大尺寸分页 可不加-->
                    <div class="js-pager pager fn-tr">
                        <ul class="pagination">
                        {!! $query->appends($filter)->render() !!}
                        </ul>
                    </div>
                    <!--END/分页-->
                </div>

            </div>
        </div>
        <!--END/主体部分-->

    </div>
</div>



<!--公共尾部-->
@include('front.common.footer')

        <!--END/公共尾部-->

<!--公用js引用-->
@include('front.common.script')

        <!--END/公用js引用-->
<script>
    var page_global={
        del_url:'../js/success.json'
    };
var opts = {
   viewBox: ".js-viewBox",
   jqP: "#orderListSel",
   listEl: ".list-item",
   toolEl: ".js-tools",
   url: page_global.del_url,
   callBacks: {
      oneSelCb: function (listItem, isSel, id) {
         tools.log(newList.getData());
      },
      allSelCb: function (listItems, isSel, ids) {
      },
      delCb: function (listItem, id) {}
   }
};
var newList = new ListSelect(opts);


//取消订单
$('.js-cancelOrder').on('click',function(e){
    var btn=$(this),
            id=btn.data('id'),
            reason='';
    layer.confirm('确定要取消该订单吗？',function(index){
        layer.close(index);
        $.ajax({

            url:'/my/order/cancelOrder'+"?"+Math.random(),
            type:'post',
            data:{order_id:id,reason:reason},
            dataType:"json",
            success:function(result){
                if (result.status){
                window.location.reload();
                }else{
                    layer.alert(result.message);
                }
            }

        });
    });

});

//确认收货
$('.fn-btn-receive').on('click', function (e) {
    e.preventDefault();
    //获取订单ID
    var btn = $(this), order_id = btn.data('id');
    layer.confirm('您确定收到货物了吗？',function(index){
        layer.close(index);
    $.ajax({
        url: '/my/order/receiveGoods' + "?" + Math.random(),
        type: 'post',
        data: {order_id: order_id, '_token': '{{csrf_token()}}'},
        dataType: "json",
        success: function (result) {
            if (result.status) {
                window.location.reload();
                //window.location.href='/my/order';
            } else {
                alert(result.message);
            }
        }

    });
    });

});
//再次购买
$('.fn-btn-payagain').on('click', function (e) {
    e.preventDefault();
    //获取订单ID
    var btn = $(this), order_id = btn.data('id'),goCart=btn.data('gocart');
    var allCartItem=$('.js-cart').find('.cart-num');

    if(typeof order_id=='undefined'||order_id==''||btn.hasClass('disabled')||btn.prop('disabled')) return false;
    btn.addClass('disabled').prop('disabled',true);
    $.ajax({
        url: '/my/order/payagain' + "?" + Math.random(),
        type: 'post',
        data: {order_id: order_id, '_token': '{{csrf_token()}}'},
        dataType: "json",
        success: function (result) {
           if (typeof result.goods_num!='undefined' && result.goods_num != ''){
               typeof layer!='undefined'&&layer.msg('已加入购物车',{
                   icon: 1,
                   offset:'10px',
                   time:2000
               });
               allCartItem.text(result.goods_num);
               if(goCart) window.location.href='/cart';//如果按钮带data="goCart"属性，成功后跳转到购物车
           } else if(typeof result.message!='undefined' && result.message != ''){
               typeof layer!='undefined'&&layer.alert(result.message);
           } else{
               typeof layer!='undefined'&&layer.msg('操作失败，请刷新页面重试！',{offset:'10px'});
           }
           that.removeClass('disabled').prop('disabled',false);
        }

    });

});

$('.js-delBtn').on('click', function (e) {
    e.preventDefault();
    var btn = $(this), order_id = btn.data('id');
    var box=btn.closest('.inner-body');
    var siblingsBox=box.siblings('.inner-body');

    layer.confirm('确定要删除该订单吗？', function (index) {
        layer.close(index);
        $.ajax({
            url: '/my/order/' + order_id + "?" + Math.random(),
            type: 'delete',
            data: {order_id: order_id, '_token': '{{csrf_token()}}'},
            dataType: "json",
            success: function (result) {
                if (result.status) {
                    box.slideUp(300,function(){
                        $(this).remove();
                        if(siblingsBox.length==0){
                            var pager=$('.js-pager').find('.active');
                            if(pager.length&&pager.next('li').hasClass('disabled')){
                                var curPage=pager.text()*1-1;
                                window.location.href = window.location.href.replace(/page=[0-9]+/,'page='+curPage);
                            }else{
                                window.location.reload();
                            }
                        }
                    });
                } else {
                    layer.alert(result.message);
                }
            }

        });
    });
});

$('.btn-search').on('click',function(e){
e.preventDefault();
var key = $('#key').val();
$.ajax({
     url: '/my/order/search' + "?" + Math.random(),
     type: 'post',
     data: {key: key, '_token': '{{csrf_token()}}'},
     dataType: "json",
     success: function (result) {
        if (result.status) {
           window.location.href='/my/order/'+result.order_id;
        }else{
            layer.alert(result.message);
        }

     }
});

});

//倒计时
$('.js-countDown').each(function(){
   var that=$(this),time=that.data('time')*1000;

    if(time>0){
        tools.buttonCountdown(that,time,'d:h:m:s','',function(){
            window.location.reload();
        });

        setTimeout(function () {
            that.prop("disabled", false).removeClass("disabled");
        }, 10);
    }else{
        that.closest('.J-wrap').remove();
    }

});

</script>
<script type="text/javascript">
    var qqNum="";
    $(".js-qq").each(function(index,e){
        var qq=$(e).data("qq");
        qqNum+=qq+":";
    });
    //动态创建javascript跨域获取QQ在线状态
    var online = [];
    var url="http://webpresence.qq.com/getonline?Type=1&"+qqNum;
    $.getScript(url)
            .done(function() {
                //scrpit加载完成后执行在线状态图片的改写

                $(".js-qq").each(function(index,e){
                    if(online[index]=="1"){
                        $(e).find(".icon").addClass('icon-qq-blue-sm').removeClass('icon-qq-gray-sm');
                        $(e).attr('title','在线');
                    }
                });
            });
</script>
</body>
</html>